package com.qf.hsr.service.impl;

import com.qf.hsr.dao.IUserMapper;
import com.qf.hsr.entity.ResultVO;
import com.qf.hsr.pojo.User;
import com.qf.hsr.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.qf.hsr.constant.MessageConstant.*;

/**
 * @author q
 * @version V1.0
 * @date 2021/11/16
 **/
@Service
public class UserServiceImpl implements IUserService {

    @Autowired
    private IUserMapper userMapper;

    @Override
    public ResultVO<List<User>> findAllUser() {
        List<User> allUser = userMapper.findAllUser();
        return ResultVO.ok(USER_QUERY_SUCCESS,allUser);
    }

    @Override
    public ResultVO deleteUserById(Integer userId) {
        Integer i = userMapper.deleteUserById(userId);
        if (i.intValue() == 1) {
            return ResultVO.ok(USER_DELETE_SUCCESS);
        }
        return ResultVO.error(USER_DELETE_FAIL);
    }

    @Override
    public ResultVO saveUser(User user) {
        Integer i = userMapper.saveUser(user);
        if (i.intValue() == 1) {
            return ResultVO.ok(USER_SAVE_SUCCESS);
        }
        return ResultVO.error(USER_SAVE_FAIL);
    }
}
